package com.kehutong.crm.app;

import com.kehutong.common.entity.Root;
import com.kehutong.common.entity.TreeUtil;
import com.kehutong.common.util.Token;
import com.kehutong.crm.entity.Tag;
import org.coraframework.inject.Inject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;

import java.util.List;

/**
 * 标签
 * @author: liukunlong
 * @date: 2021-03-06 14:23
 */
@MvcAction
@ReqMapping("/kht-bin/tag")
public class TagAction {
    @Inject
    private JdbcSession jdbcSession;

    /**
     * 获取标签列表
     *
     * @param token 用户信息
     * @return 标签列表
     */
    @ReqMapping("/listTag")
    public Object listTag(Token token) {
        final List<Tag> tagList = jdbcSession.findArray(Tag.class)
                .eq("deleted", false)
                .exe();
        final Tag root = Pool.newInstance(Tag.class, Root.ROOT_ID);
        tagList.add(root);
        return Result.success(TreeUtil.organizeAsTree(tagList, false));
    }
}
